package com.bestcem.xm.ticket.enums;

import lombok.Getter;
import lombok.ToString;

import java.util.Objects;

/**
 * ticket 状态枚举
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/10 17:24
 */
@Getter
@ToString
public enum TicketStatusEnum {
    /**
     * CREATED
     */
    CREATED("CREATED", 0),
    /**
     * FOLLOWING
     */
    FOLLOWING("FOLLOWING", 1),
    /**
     * AUDITING
     */
    AUDITING("AUDITING", 2),
    /**
     * MANUAL_CLOSED
     */
    MANUAL_CLOSED("MANUAL_CLOSED", 3),
    /**
     * SYSTEM_CLOSED
     */
    SYSTEM_CLOSED("SYSTEM_CLOSED", 4),
    /**
     * 关闭
     */
    CLOSED("关闭", 5),
    /**
     * 工单处理完成
     */
    FINISH("工单处理完成", 6),
    /**
     * 工单处理失败
     */
    FAILED("工单处理失败", 7),
    /**
     * 无需跟进处理
     */
    UNNEED_DEAL("无需跟进处理", 8),
    /**
     * 删除
     */
    DELETED("删除", 9);

    private final String name;

    private final Integer index;

    TicketStatusEnum(String name, Integer index) {
        this.name = name;
        this.index = index;
    }

    /**
     * 根据 index 获取枚举实体
     * 找不到则返回 null
     *
     * @param index 枚举index
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/8/17 20:31
     */
    public static TicketStatusEnum getByIndex(Integer index) {
        if (Objects.isNull(index)) {
            return null;
        }
        for (TicketStatusEnum value : values()) {
            if (value.getIndex().equals(index)) {
                return value;
            }
        }
        return null;
    }
}
